local bujihuoying = fk.CreateSkill{
    name = "ym2__bujihuoying",
    tags = {Skill.Spirited},
}
Fk:loadTranslationTable{
    ["ym2__bujihuoying"] = "不羁火鹰",
    [":ym2__bujihuoying"] = "昂扬技，出牌阶段，你可以将任意张牌移出游戏至等量个回合结束，视为使用一张【万箭齐发】与【五谷丰登】，且你可以为这些牌减少一个目标。<br>激昂：当因此移出的牌移回时，你弃置其中一张。",
    ["$ym2__bujihuoying"] = "不羁火鹰",
    ["#ym2__bujihuoying-choose"] = "不羁火鹰：为 %arg 取消一个目标",
    ["#ym2__bujihuoying-discard"] = "不羁火鹰：弃置其中一张牌",

    ["$ym2__bujihuoying1"] = "准备好了吗？",
    ["$ym2__bujihuoying2"] = "英雄登场！",
    ["$ym2__bujihuoying3"] = "续写传奇！",
}
bujihuoying:addEffect("active",{
    audio_index = {1,2},
    min_card_num = 1,
    card_filter = Util.TrueFunc,
    can_use = function (self, player)
        return player:hasSkill(bujihuoying.name) and player:getMark(bujihuoying.name) == 0
    end,
    on_use = function (self, room, effect)
        local player = effect.from
        local cards = effect.cards
        room:addPlayerMark(player,bujihuoying.name,#cards)
        player:addToPile("$ym2__bujihuoying", cards, false, bujihuoying.name, player.id)
        for _, name in ipairs({"archery_attack","amazing_grace"}) do
            local card = Fk:cloneCard(name)
            card.skillName = bujihuoying.name
            local targets = table.filter(room:getAlivePlayers(), function (p)
                return not player:isProhibited(p, card) and player:canUseTo(card,p)
            end)
            if #targets > 0 then
                room:useVirtualCard(name, nil, player, targets, bujihuoying.name)
            end
        end
    end,
    times = function (self, player)
        return player:getMark(bujihuoying.name) ~= 0 and player:getMark(bujihuoying.name) or -1
    end,
    enabled_at_play = function(self, player)
        return not player:isNude() and player:getMark(bujihuoying.name) == 0
    end,
    enabled_at_response = function(self, player, response)
        return not response and not player:isNude() and player:getMark(bujihuoying.name) == 0
    end,
})
bujihuoying:addEffect(fk.AfterCardTargetDeclared, {
    anim_type = "control",
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        return target == player and data.card and data.card.skillName == "bujihuoying" and #data.tos > 0
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local to = room:askToChoosePlayers(player, {
            targets = data.tos,
            min_num = 1,
            max_num = 1,
            prompt = "#ym2__bujihuoying-choose:::"..data.card:toLogString(),
            skill_name = bujihuoying.name,
            cancelable = true,
        })
        if #to > 0 then
            event:setCostData(self, {tos = to})
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        data:removeTarget(event:getCostData(self).tos[1])
    end,
})
bujihuoying:addEffect(fk.TurnEnd, {
    mute = true,
    can_refresh = function(self, event, target, player, data)
        return not player.dead and #player:getPile("$ym2__bujihuoying") > 0
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        room:removePlayerMark(player,bujihuoying.name,1)
        if player:getMark(bujihuoying.name) == 0 then
            player:broadcastSkillInvoke(bujihuoying.name,3)
            local cards = player:getPile("$ym2__bujihuoying")
            local throw = room:askToChooseCard(player, {
                target = player,
                flag = { card_data = {{ "$ym2__bujihuoying", cards }} },
                skill_name = bujihuoying.name,
                prompt = "#ym2__bujihuoying-discard",
            })
            table.removeOne(cards,throw)
            room:moveCardTo(throw,Card.DiscardPile,nil,fk.ReasonDiscard,bujihuoying.name,nil,nil,player)
            if #cards > 0 then
                room:moveCardTo(cards, Player.Hand, player, fk.ReasonPrey, bujihuoying.name)
            end
        end
    end,
})
return bujihuoying